package MTProxyServer;

import java.io.*;
import java.net.*;

public class ServerThread extends Thread
{
	// The Server that spawned us
	private Server server = null;
	// The Socket connected to our client
	private Socket socket = null;
	
	// Constructor.
	public ServerThread( Server server, Socket socket ) 
	{
		// Save the parameters
		this.server = server;
		this.socket = socket;

		//Start up the thread
		start();
	}
	
	//This runs in a separate thread when start() is called in the
	//constructor.
	public void run() 
	{
		try {
			//Create a DataInputStream for communication; the client
			//is using a DataOutputStream to write to us
			
			MessageCentre mMSGCenter = new MessageCentre( 
					new DataInputStream( socket.getInputStream() ),
					new DataOutputStream( socket.getOutputStream() ) );
			
			mMSGCenter.ReceiveMSG();
		} 
		catch( EOFException ie ) {
			//This doesn't need an error message
		} 
		catch( IOException ie ) {
			//This does; tell the world!
			ie.printStackTrace();
		} 
		finally {
			//The connection is closed for one reason or another,
			//so have the server dealing with it
			try {
				socket.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			//server.removeConnection( socket );
		}
	}
	
	
}